/**
 *  File name:     FullScreenTest.java
 *  Package name:  infiniteloop.samples.display
 *  Project name:  InfiniteLoop
 *  Author:        Miloš Mihajlović
 *  Year:          2011
 *  Description:   
 */

package infiniteloop.samples.display;

import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JFrame;

public class FullScreenTest extends JFrame {

	/**
	 * serial version UID
	 */
	private static final long serialVersionUID = 5036936088542433026L;

	/**
	 * for testing purposes
	 */
	private boolean antialiasing = false;
	
	/**
	 * the string that is being drawn
	 */
	private String str = "Who cares what's written!";
	
	public void run(DisplayMode dm) {
		setAlwaysOnTop(true);
		toFront();
		repaint();
		setBackground(Color.BLUE);
		setForeground(Color.RED);
		setFont(new Font("Verdana", Font.PLAIN, 50));
		Screen s = new Screen();
		try {
			s.setFullScreen(dm, this);
			setAntialiasing(false);
			repaint();
			Thread.sleep(500);
			setAntialiasing(true);
			repaint();
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally {
			s.restoreScreen();
		}
	}
	
	public void setAntialiasing(boolean antialiasing) {
		this.antialiasing = antialiasing;
	}
	
	public boolean isAntialiasing() {
		return antialiasing;
	}
	
	@Override
	public void paint(Graphics g) {
		// Adding anti-aliasing to text fonts
		if (antialiasing && g instanceof Graphics2D) {
			Graphics2D g2d = (Graphics2D) g;
			g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		}
		// Drawing a string
		if (antialiasing) {
			g.drawString(str, 200, 200);
		} else {
			g.drawString(str, 200, 150);
		}
		
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int width = 1920;
		int height = 1080;
		int bitDepth = DisplayMode.BIT_DEPTH_MULTI;
		int refreshRate = DisplayMode.REFRESH_RATE_UNKNOWN;
		DisplayMode dm = new DisplayMode(width, height, bitDepth, refreshRate);
		FullScreenTest frame = new FullScreenTest();
		frame.run(dm);
	}

}
